export async function timer(img_url) {
    if (!img_url) {
        return
    }

    const transmitResult = {
        startTime: performance.now(),
        endTime: 0,
        latency: 0,
        duration: 0,
        fileSize: 0,
        speed: 0,
        blob_url: ""
    }
    let contentLength = 0

    const blob = await fetch(img_url).then(response => {
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`);
        } else {
            transmitResult.latency = performance.now() - transmitResult.startTime
            transmitResult.startTime = performance.now()
            contentLength = response.headers.get('Content-Length');
            if (contentLength) {
                transmitResult.fileSize = parseInt(contentLength, 10)
            } else {
                transmitResult.fileSize = 'unknown'
            }
            return response.blob();
        }
    })
    const objectURL = URL.createObjectURL(blob);
    transmitResult.endTime = performance.now()
    transmitResult.duration = transmitResult.endTime - transmitResult.startTime
    transmitResult.speed = transmitResult.fileSize / (transmitResult.duration / 1000)
    transmitResult.blob_url = objectURL;
    return transmitResult;
    //const appDiv = document.getElementById('app');
    //appDiv.style.backgroundImage = `url(${objectURL})`;
    //URL.revokeObjectURL(objectURL);
}